<template>
 <van-picker
  title="性别"
  show-toolbar
  :columns="columns"
  :default-index="value"
  @confirm="onConfirm"
  @cancel="$emit('close')"
/>
</template>

<script>
import { updateUserInfo } from '@/api/user.js'
import { Toast } from 'vant'
export default {
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  data () {
    return {
      columns: ['男', '女']

    }
  },

  created () {

  },

  methods: {
    async  onConfirm (val, index) {
      Toast.loading({
        message: '加载中...',
        forbidClick: true

      })
      try {
        await updateUserInfo({
          gender: index
        })
        console.log(val)
        Toast.success('修改成功')
        this.$emit('close')
        this.$emit('input', index)
      } catch (err) {
        Toast.fail('修改失败')
      }
    }
  }
}
</script>

<style scoped lang='less'>

</style>
